const request = require('../../../utils/request.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    opts: ["进入店铺", "取消关注"],
    saved_shop: []
  },
  onLoad: function(e) {

  },
  onShow: function(e) {
    var that = this;
    var url = request.URL + '/collection/store';
    request.request({
      url: url,
      data: {
        userId: 1
      },
      success: function(res) {
        console.log(res);
        var saved_shop = res.data;
        that.setData({
          saved_shop: saved_shop
        })
      },
      fail: function() {
        request.showFailInfo()
      }
    })
  },
  //选择
  chooseOpt: function(e) {
    var that = this;
    console.log(e);
    var opt = e.detail.value;
    switch (opt) {
      case "0":
        that.toStore(e);
        break;
      case "1":
        console.log("delete")
        that.unsaved(e);
        break;
    }
  },
  //取消收藏
  unsaved: function(e) {
    var that = this;
    wx.showModal({
      title: '取消收藏',
      content: '点击确定取消收藏',
      success: function(res) {
        if (res.confirm) {
          var storeColId = e.target.dataset.unsave;
          console.log(storeColId);
          var url = request.URL + '/collection/store/delete';
          request.request({
            url: url,
            data: {
              storeColId: storeColId
            },
            success: function(res) {
              that.onShow();
              console.log(res)
            },
            fail: function() {
              request.showFailInfo()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  //进入店铺
  toStore: function(e) {

    console.log(e)
    var storeId = e.target.dataset.set;
    var url = '/pages/details/shop_details/shop_details' + '?storeId=' + storeId;
    console.log(url)
    wx.navigateTo({
      url: url,
    })
  },
  // onShareAppMessage: function () {
  //   return {
  //     title: '自定义转发标题',
  //     path: '/page/user?id=123',
  //     success: function (res) {
  //       var shareTickets = res.shareTickets;
  //       if (shareTickets.length == 0) {
  //         return false;
  //       }
  //       wx.getShareInfo({
  //         shareTicket: shareTickets[0],
  //         success: function (res) {
  //           var encryptedData = res.encryptedData;
  //           var iv = res.iv;
  //         }
  //       })
  //     },
  //     fail: function (res) {
  //       // 转发失败
  //     }
  //   }
  // },
})